<template>
    <div>
        <!-- <div>5464556456</div> -->
      <el-card>
        <el-table :data="tableData" style="width: 100%">
          <el-table-column
            prop="content"
            label="内容"
            width="180"
          ></el-table-column>
          <el-table-column
            prop="approve"
            label="点赞次数"
            width="180"
          ></el-table-column>
          <el-table-column
            prop="reportFlag"
            label="状态"
            width="180"
          >
          <template #default="scope">
             <el-tag :type="scope.row.reportFlag ? 'warning' :'success'">
                {{ scope.row.reportFlag ? '异常' :'正常' }}
             </el-tag>
            </template>
        </el-table-column>
        
          <el-table-column
            prop="date"
            label="创建时间"
            width="250"
          >
          <template #default="scope">
              {{ formDataMoment(scope.row.date) }}
            </template>
        </el-table-column>
          <el-table-column prop="action" label="操作">
            <template #default="scope">
              
              <el-popconfirm
                title="确认删除吗"
                confirm-button-text="确认"
                cancel-button-text="删除"
                @confirm="handleDelete(scope.row._id)"
              >
                <template #reference>
                  <el-button size="small" type="danger">删除</el-button>
                </template>
              </el-popconfirm>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination background layout="prev, pager, next" :total="total"  @current-change="handleCurrentChange" :page-size="10"/>
      </el-card>
     
    </div>
  </template>
  
  <script setup>
  import { ref, onMounted, reactive } from "vue";
  import axios from "axios";
  import { ElMessage, ElMessageBox } from "element-plus";
  import myUtil from "../../util/util.js"
  import moment from "moment";
  const tableData = ref([]);
  const userFormRef = ref();
  const total = ref(0);
  const params = ref({
    pageNo:1,
    orderId:1,
    questionId:'undefined'
  })
  
  
  const formDataMoment = (date) => {
        return moment(date).format("YYYY-MM-DD HH:mm:ss")
  };
  const handleCurrentChange = (e) => {
    params.value.pageNo = e
    getList();
}
  const publishChange = async(item) => {
 
    let res = await axios.post("/wxapi/user/changeVip",{
      userId:item._id,
      flag:item.vip
    });
    if(res.data.code == 200) {
      ElMessage.success("操作成功");
      //getList();
    }else {
      ElMessage.success("操作失败");
    }
    console.log('111')
  }
  const handleDelete = async (id) => {
    let res = await axios.post(`/wxapi/comment/deleteComment`,{
      commentId:id
    });
    if (res.data.code == 200) {
      ElMessage.success("操作成功");
      getList();
    } else {
      ElMessage.success("操作失败");
    }
  };
  onMounted(() => {
    
    getList();
  });
  
  
  const getList = async () => {
    let res = await axios.get("/wxapi/comment/getCommentList",
    {
    params:params.value
  });
  if(res.data.code == 200) {
    tableData.value = res.data.data.result;
    total.value = res.data.data.total;
    console.log("res", res.data);
  }
   
  };
  </script>